package Zifuchuang;

import java.util.Arrays;

public class zifuchuang {
    public static void main(String[] args) {
        String s = "Hello";
        System.out.println(s);
        s = s.toUpperCase();
        System.out.println(s);
        String s1 = "hello";
        String s2 = "hello";
        System.out.println(s1 == s2);
        System.out.println(s1.equals(s2));

        String s3 = "HELLO".toLowerCase();
        System.out.println(s1 == s3);
        System.out.println(s1.equals(s3));

//        String s4 = "Hi %s, your score is %d!";
//        System.out.println(s4.formatted("Alice", 80));
//        System.out.println(String.format("Hi %s, your score is %.2f!", "Bob", 59.5));
//
        //要把任意基本类型或引用类型转换为字符串，可以使用静态方法valueOf()
        String.valueOf(123); // "123"
        String.valueOf(45.67); // "45.67"
        String.valueOf(true); // "true"
        String.valueOf(new Object()); // 类似java.lang.Object@636be97c

        //要把字符串转换为其他类型，就需要根据情况
        int n1 = Integer.parseInt("123"); // 123
        int n2 = Integer.parseInt("ff", 16); // 按十六进制转换，255

        //把字符串转换为boolean类型：
        boolean b1 = Boolean.parseBoolean("true"); // true
        boolean b2 = Boolean.parseBoolean("FALSE"); // false

        //要特别注意，Integer有个getInteger(String)方法，它不是将字符串转换为int，而是把该字符串对应的系统变量转换为Integer：
        Integer.getInteger("java.version"); // 版本号，11

        //String和char[]类型可以互相转换，方法是：
        //如果修改了char[]数组，String并不会改变
        char[] cs = "Hello".toCharArray(); // String -> char[]
        String ss = new String(cs); // char[] -> String
        System.out.println(ss);
        cs[0] = 'X';
        System.out.println(ss);

        int[] scores = new int[] { 88, 77, 51, 66 };
        Score sss = new Score(scores);
        sss.printScores();
        scores[2] = 99;
        sss.printScores();
    }
}
class Score {
    private int[] scores;
    public Score(int[] scores) {
        this.scores = scores;
    }

    public void printScores() {
        System.out.println(Arrays.toString(scores));
    }
}